// 某个模块的数据请求（增删改查！）

import $axios from "@/common/http";  // 封装的axios
import axios from "axios"   // 原生的axios
import { Message } from "element-ui"  // 提示框


/**
 * 
 * @param {*} data  { id:id }  { size:每页数量  page:页码数 }
 */
export async function getGoods(data) {
    let res;
    if (data.id) {
        res = await $axios.get("/goodsinfo", { params: data });
    } else {
        res = await $axios.get("/goodslist", { params: data });
    }
    return res.list;
}

export async function getTotal() {
    let res = await $axios.get("/goodscount");
    return res.list[0].total;
}

// 根据分类来获取商品列表
export async function getCategoryGoods(topid,childid){
    let res = await $axios.get("/goodslist", { params: { fid:topid,sid:childid } });
    return res.list;
}

export async function addGoods(data) {
    let res = await $axios.post("/goodsadd", data);
    Message.success(res.msg)
    return true;
}

export async function editGoods(data) {
    let res = await $axios.post("/goodsedit", data);
    Message.success(res.msg)
    return true;
}

export async function delGoods(id) {
    if (!id) {
        Message.warning("请传入删除id");
        return;
    }
    let res = await $axios.post("/goodsdelete", { id })
    Message.success(res.msg)
    return res.list;
}
